var mysql = require("mysql");

var pool  = mysql.createPool({
    connectionLimit:10,
    user:"root",
    password:"123456",
    database:"timtest"
})

var query = function(sql) {
    return new Promise((resolve,reject)=>{
        pool.getConnection(function(err,connection){
            if(!err) {
                try {
                    console.log(sql);
                    connection.query(sql,function (qerr,rows,fields) {
                        //关闭连接
                        connection.release();
                        //回调
                        resolve(rows);
                    })
                } catch (error) {
                    reject(error,null,null);
                }
            }else{
                reject(err,null,null);
            }
        })
    })
}

module.exports = query;